/**
 * @file    jm_frame_port.c
 * @brief   关节电机数据帧接口服务
 * @details This is the detail description.
 * @author  wang-haoyu
 * @date    2025年7月10日 (created)
 * @version 0.0.1
 * @par Copyright (C):
 *          All Rights Reserved.
 * @par Encoding:
 *          UTF-8
 * @par Description        :
 * 1. Hardware Descriptions:
 *      None.
 * 2. Program Architecture:
 *      None.
 * 3. File Usage:
 *      None.
 * 4. Limitations:
 *      None.
 * 5. Else:
 *      None.
 * @par Modification:
 * -# Date          : 2025年7月10日;
 * Revision         : 0.0.1;
 * Author           : wang-haoyu;
 * Contents         :
 */
 
/* =============================================================================
 *                                header files
 * ========================================================================== */
#ifndef __JM_FIFO_PORT_H
#define __JM_FIFO_PORT_H

#include "jm_config.h"
#include "utils_easyfifo.h"
#include "jm_error_code.h"
#include "data.h"
#include "utils.h"

/* =============================================================================
 *                              macros & constants
 * ========================================================================== */

/* =============================================================================
 *                          data structure definitions
 * ========================================================================== */

typedef struct 
{
    easy_fifo_t *(*jm_fifo_creat)(const char *name, unsigned int total_size, bool lock_enable);
    void (*jm_fifo_destroy)(easy_fifo_t *fifo);
    int (*jm_fifo_get_used)(easy_fifo_t *fifo);
    int (*jm_fifo_get_free)(easy_fifo_t *fifo);
    int (*jm_fifo_write)(easy_fifo_t *fifo,const void *src,unsigned int count);
    int (*jm_fifo_read)(easy_fifo_t *fifo,void *r_buffer,unsigned int count);
    int (*jm_fifo_pick)(easy_fifo_t *fifo,void *r_buffer,unsigned int count);
    int (*jm_fifo_cut)(easy_fifo_t *fifo,unsigned int count);
    void (*jm_fifo_clean)(easy_fifo_t *fifo);
}jm_fifo_operat_t;

typedef struct 
{
    easy_fifo_t *fifo;
    char *fifo_name;
    rt_uint32_t fifo_size;
}jm_fifo_port_t;

/* =============================================================================
 *                         static variable definitions
 * ========================================================================== */

/* =============================================================================
 *                         static function definitions
 * ========================================================================== */

/* =============================================================================
 *                         global function definitions
 * ========================================================================== */
/*
 * 关节电机数据帧创建函数
 *
 * Parameter:
 *   Input:
 *		-*obj：fifo接口句柄
 *   Output:
 * Returns:
 *		-JM_FIFO_ENOERR_CODE：返回状态
 */
JM_FIFO_ENOERR_CODE jm_drv_fifo_creat(jm_fifo_port_t *obj);

/*
 * 关节电机数据帧销毁函数
 *
 * Parameter:
 *   Input:
 *		-*obj：fifo接口句柄
 *   Output:
 * Returns:
 *		-JM_FIFO_ENOERR_CODE：返回状态
 */
JM_FIFO_ENOERR_CODE jm_drv_fifo_release(jm_fifo_port_t *obj);

/*
 * 关节电机数据帧写入函数
 *
 * Parameter:
 *   Input:
 *		-*obj：fifo接口句柄
 *   Output:
 * Returns:
 *		-JM_FIFO_ENOERR_CODE：返回状态
 */
JM_FIFO_ENOERR_CODE jm_drv_fifo_write(jm_fifo_port_t *obj,const void *wbuf,rt_uint32_t size);

/*
 * 关节电机数据帧读取函数
 *
 * Parameter:
 *   Input:
 *		-*obj：fifo接口句柄
 *   Output:
 * Returns:
 *		-JM_DRV_ENOERR_CODE：返回状态
 */
int jm_drv_fifo_read(jm_fifo_port_t *obj,void *rbuf,rt_uint32_t size);

/*
 * 关节电机数据fifo获取使用内存大小函数
 *
 * Parameter:
 *   Input:
 *		-*obj：fifo接口句柄
 *   Output:
 * Returns:
 *		-JM_DRV_ENOERR_CODE：返回状态
 */
int jm_drv_fifo_get_used(jm_fifo_port_t *obj);

#endif

/*******************************************************************************
 *                                  EOF
 ******************************************************************************/